/*
 * @Descripttion: 
 * @version: 
 * @Author: turingchang
 * @Date: 2020-12-17 09:53:44
 * @LastEditors: turingchang
 * @LastEditTime: 2020-12-17 17:08:32
 */

"use strict";

const enums = require("../../enum/enums");
const utils = require("../../common/utils");
const { pushParamsCompose } = require("./help");
const resformat = require("./resformat");

/**
 * @name push(自定义推送，用户可以自由配置以下属性)
 * @param {*} params
 * @returns {Promise}
 */
exports.push = async function (params) {
    const res = await this.request(enums.mobpush_api_url.push.value, pushParamsCompose(params));
    return resformat.pushRes(res);
};


/**
 * @name pushAll(广播推送)
 * @param {string} workNo 任务标识
 * @param {string} title 推送标题
 * @param {string} content 推送内容
 *
 */
exports.pushAll = async function (workNo, title, content) {
    const res = await this.push({
      workNo: workNo,
      pushNotify: {
        content: content,
        title: title,
      },
      pushTarget: {
        target: TARGET_ALL,
      },
    });
    return res;
  };
  
  /**
   * @name pushByAlias(别名推送)
   * @param {string} workNo 任务标识
   * @param {string} title 推送标题
   * @param {string} content 推送内容
   * @param {string} alias  别名，可以传入多个
   */
  exports.pushByAlias = async function (workNo, title, content, alias) {
    if (alias && Object.prototype.toString.call(alias) !== "[object String]") {
      throw new Error("alias须字符串类型");
    }
    const res = await this.push({
      workNo: workNo,
      pushNotify: {
        content: content,
        title: title,
      },
      pushTarget: {
        target: TARGET_ALIAS,
        alias: alias && alias.split(","),
      },
    });
    return res;
  };